<?php
/**
 * Created by PhpStorm.
 * User: Administrator
 * Date: 2015/9/7
 * Time: 11:12
 */

namespace Admin\Controller;


use Think\Controller;

class CountController extends Controller {
        public function index(){
            $this->display();
        }

    //返工记录列表
    public function returnList(){
        $obj = M("order_record");
        $obj2 = M("user_main");
        $orderp = M("order_profile");
        $datas = $obj->select();
        $lists = [];
        foreach($datas as $da){
            $user = $obj2->where("uid=".$da["uid"])->find();
            $list["name"] = $user["name"];
            $list["ordernum2"] = $da["ordernum2"];
            $orderpArr = $orderp->where("orderNum2='".$da["ordernum2"]."'")->find();
            $list["belong"] = $orderpArr["belong"];
            $list["type"] = $da["type"];
            $list["num"] = $da["num"];
            $list["descr"] = $da["descr"];
            $list["return_date"] = $da["return_date"];
            $list["gc"] = $da["gc"];
            $lists[] = $list;
        }
        $this->assign("lists",$lists);
        $this->display();
    }

    //返工记录导出excel
    public function returnListExport(){
        $postData = I("post.");
        $obj = M("order_record");
        $obj2 = M("user_main");
        $list = $obj->where("ordertime>=UNIX_TIMESTAMP('" . $postData["start_time"] . "') and ordertime<UNIX_TIMESTAMP('" . $postData["end_time"] . "')")->select();
        $datas = [];
        foreach ($list as $l) {
            $user = $obj2->where("uid=".$l["uid"])->find();
            $data["name"] = $user["name"];
            $data["ordernum2"] = $l["ordernum2"];
            $data["type"] = $l["type"];
            $data["num"] = $l["num"];
            $data["descr"] = $l["descr"];
            $data["return_date"] = $l["return_date"];
            $data["gc"] = $l["gc"];

            $datas[] = $data;
        }
        exportexcel($datas, ["姓名", "订单号", "衣服类型", "数量", "返工理由", "返工日期","工厂"], "返工记录");
    }
} 